import gugga.collections.ArrayList;
import gugga.collections.IIterator;

import test_framework.test.unit.TestCase;

/**
 * @author stefan
 */
class guggaLibTests.ArrayListIteratorTest
		extends TestCase
{
	function ArrayListIteratorTest() 
	{
		super();
	}
	
	function testIteration ()
	{
		var obj1 : Object = new Object();
		var obj2 : Object = new Object();
		var obj3 : Object = new Object();
		
		var list : ArrayList = new ArrayList();
		list.addItem(obj1);
		list.addItem(obj2);
		list.addItem(obj3);
		
		var iterator : IIterator = list.getIterator();
		assertThrowsWithFunctionAndMessage(
			"iterator.current() should raise an exception after creation", 
			iterator, 
			iterator.current, 
			null
		);
	
		iterator.iterate();
		assertEquals(
			"iterator.current() should be equal to obj1",
			obj1,
			iterator.current()
		);
		
		iterator.iterate();
		
		assertEquals(
			"iterator.current() should be equal to obj2",
			obj2,
			iterator.current()
		);

		iterator.iterate();
		
		assertEquals(
			"iterator.current() should be equal to obj3",
			obj3,
			iterator.current()
		);
		
		assertFalse(
			"iterate() should be false when the cursor reachs end of list",
			iterator.iterate()
		);
		
		iterator.reset();
		assertThrowsWithFunctionAndMessage(
			"iterator.current() should raise an exception after reset", 
			iterator, 
			iterator.current, 
			null
		);
	}
}